package cn.kgc.vue.service.impl;

import cn.kgc.vue.common.ResponseResult;
import cn.kgc.vue.common.ResponseStatus;
import cn.kgc.vue.dto.ScoreTop;
import cn.kgc.vue.form.ScoreLsitForm;
import cn.kgc.vue.form.StudentLsitForm;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.vue.entity.Score;
import cn.kgc.vue.service.ScoreService;
import cn.kgc.vue.mapper.ScoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
* @author 
* @description 针对表【score】的数据库操作Service实现
* @createDate 2023-08-21 09:56:22
*/
@Service
public class ScoreServiceImpl extends ServiceImpl<ScoreMapper, Score>
    implements ScoreService{

    @Autowired
    private ScoreMapper scoreMapper;

    @Override
    public ResponseResult getlist(ScoreLsitForm scoreLsitForm) {
        //获取分页和模糊
        ResponseResult responseResult = new ResponseResult();
        Page<Score> page = new Page<>(scoreLsitForm.getPage(), scoreLsitForm.getLimit());
        LambdaQueryWrapper<Score> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(scoreLsitForm.getStudentName()),Score::getStudentName,scoreLsitForm.getStudentName());
        Page<Score> scorePage = scoreMapper.selectPage(page, wrapper);
        long total = scorePage.getTotal();
        List<Score> records = scorePage.getRecords();
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("score",records);
        responseResult.success(ResponseStatus.SUCCESS,map);
        return responseResult;
    }

    @Override
    public ResponseResult getscorelist() {
        ResponseResult responseResult = new ResponseResult();
        List<Score> list= scoreMapper.getscorelist();
        responseResult.success(ResponseStatus.SUCCESS,list);
        return responseResult;
    }

    @Override
    public ResponseResult getscoretop() {
        ResponseResult responseResult = new ResponseResult();
        //获取排名
       List<ScoreTop>  list=scoreMapper.getscoretop();
       responseResult.success(ResponseStatus.SUCCESS,list);
        return responseResult;
    }

}




